/**
 * 
 */
package ads.engenharia.dal;

import java.sql.Connection;
import java.sql.SQLException;

import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;

/**
 * @author Lanedraex
 *
 */
public class ConnectionFactory {

    private static BoneCP gpool = null;
    @SuppressWarnings("unused")
    private static final ConnectionFactory connFactory = new ConnectionFactory();

    private ConnectionFactory() {
            try {
                    BoneCPConfig config = new BoneCPConfig();
                    config.setJdbcUrl("jdbc:sql://localhost:port/dbName");
                    config.setUser("dbUser");
                    config.setPassword("dbPassword");
                    config.setMinConnectionsPerPartition(3);
                    config.setMaxConnectionsPerPartition(50);
                    config.setPartitionCount(1);

                    gpool = new BoneCP(config);
            } catch (SQLException e) {
                    e.printStackTrace();
            }
    }

    public static Connection getConnection() throws SQLException {
            Connection conn = gpool.getConnection();
            return conn;
    }

    public static void close(Connection conn) throws SQLException {
            conn.close();
    }

    public static void shutdown() throws SQLException {
            gpool.shutdown();
    }

}
